package com.yiqi.liebang.feature.home.view;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;

import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.AdvancedWebView;
import com.yiqi.liebang.entity.bo.HomeBo;

import butterknife.BindView;

public class BannerWebActivity extends BaseActivity implements AdvancedWebView.Listener {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.fullWebView)
    AdvancedWebView mWebview;
    HomeBo.IndexBannerBean mBannerBean;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_banner_web;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initData() {
        mBannerBean = (HomeBo.IndexBannerBean) this.getIntent().getSerializableExtra("banner");
        if (mBannerBean != null) {
            initToolBar(mToolbar, TextUtils.isEmpty(mBannerBean.getTitle())?"":mBannerBean.getTitle(), true, true);
            mWebview.loadUrl(mBannerBean.getTurnUrl());
            mWebview.setListener(this, this);
            mWebview.setGeolocationEnabled(true);
        }
    }

    @SuppressLint("NewApi")
    @Override
    protected void onResume() {
        super.onResume();
        if (mWebview != null)
            mWebview.onResume();

    }

    @SuppressLint("NewApi")
    @Override
    protected void onPause() {
        if (mWebview != null)
            mWebview.onPause();
        // ...
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        if (mWebview != null)
            mWebview.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onPageStarted(String url, Bitmap favicon) {
        showLoading();
    }

    @Override
    public void onPageFinished(String url) {
        dismissLoading();
    }

    @Override
    public void onPageError(int errorCode, String description, String failingUrl) {
        T.showShort(description);
        dismissLoading();
    }

    @Override
    public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {

    }

    @Override
    public void onExternalPageRequest(String url) {

    }
}